<template>
	<div id="app">
		<!-- <div class="layer"> -->
		<router-view v-if="pageShow" />
		<!-- </div> -->
	</div>
</template>
<script>
	import Cookie from 'vue-cookies'
	import Fingerprint2 from 'fingerprintjs2'
	export default {
		components: {},
		computed: {
			userInfo() {
				return this.$store.state.userInfo
			}
		},
		data() {
			return {
				pageShow: false, // 
			}
		},
		watch: {},
		created() {
			let {
				token,
				language
			} = this.$route.query
			// console.log('token111', this.$route.query, token);
			if (token) {
				localStorage.setItem('TOKEN', token)
			}
			if (language) {
				this.$i18n.locale = language
				localStorage.setItem('lang', language)
			}
		},
		async mounted() {

			// 当窗口滚动时，调用上面的函数并在控制台打印滚动条的距离
			window.onscroll = () => {
				// if (this.$utils.isSafari()) {
				const top = this.getScrollTop()
				if (top <= 20) {
					var body = document.body;
					body.style.setProperty('overscroll-behavior', 'none')
				} else {
					var body = document.body;
					body.style.setProperty('overscroll-behavior', 'auto')
				}
				// }
			}
			try {
				this.getFingerprint()
				this.pageShow = true
			} catch (e) {
				//TODO handle the exception
				this.pageShow = true
			}

			// console.log('Fingerprint::', localStorage.getItem('Fingerprint'));

			await this.$store.dispatch('getMatches')
			const token = localStorage.getItem('TOKEN')
			// console.log('token:::', token);
			if (token) {
				this.$store.dispatch('startCountdown')
				this.$store.dispatch('getUserInfo')
				this.$store.dispatch('getBalance')
			} else {
				this.$store.dispatch('testLogin')
			}
			// 内嵌时候 告诉上层页面高度
			this.iframePostMessage()
		},
		methods: {
			iframePostMessage() {
				let height = document.getElementById('app').clientHeight
				window.parent.postMessage({
					clientHeight: height,
				}, '*')
			},
			// 获取浏览器指纹
			async getFingerprint() {
				await new Promise((resolve, reject) => {
					Fingerprint2.get(async (components) => {
						try {
							const values = components.map(function(component, index) {
								if (index === 0) { //把微信浏览器里UA的wifi或4G等网络替换成空,不然切换网络会ID不一样
									return component.value.replace(/\bNetType\/\w+\b/, '')
								}
								return component.value
							})
							// 生成最终id murmur   
							localStorage.setItem('Fingerprint', Fingerprint2.x64hash128(values.join(''), 31));
							resolve();
						} catch (e) {
							//TODO handle the exception
							reject()
						}
					})
				})
			},
			// 获取滚动距离
			getScrollTop() {
				let scrollTop = 0;
				// 如果文档的元素存在，并且文档的元素有滚动条距离
				if (document.documentElement && document.documentElement.scrollTop) {
					scrollTop = document.documentElement.scrollTop;
				}
				// 如果上面条件不满足，那么检查document.body是否有滚动条距离
				else if (document.body) {
					scrollTop = document.body.scrollTop;
				}
				// 返回滚动条的距离
				return scrollTop;
			}
		}
	}
</script>

<style lang="less">
	#app {
		font-family: PingFang SC, Microsoft YaHei, Avenir, Helvetica, Arial, sans-serif;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		text-align: center;
		color: #fff;
		font-size: 14px;
		background-color: #161D26;
		min-height: 100vh;
	}

	body {


		// .el-message {
		// 	min-width: 124px;
		// 	padding: 15px 30px;
		// 	background: #FFFFFF;
		// 	border: none;
		// 	border-radius: 10px;
		// 	z-index: 2010;
		// }

		// .el-message--success {
		// 	.el-icon-success {
		// 		color: #FFCD45;
		// 	}
		// }

		// .el-message--info .el-message__content,
		// .el-message--error .el-message__content,
		// .el-message--warning .el-message__content,
		// .el-message--success .el-message__content {
		// 	color: #1A1A1A;
		// }


		// @media screen and (max-width: 750px) {
		.el-message {
			min-width: 150px;
			padding: 10px 20px;
			background: rgba(0, 0, 0, .9);
			border: none;
			border-radius: 8px;
			// top: 50% !important;
			// transform: translate(-50%, -50%);
			// display: block;


		}

		.el-message {

			.el-icon-error,
			.el-icon-info,
			.el-icon-success,
			.el-icon-warning {
				color: #fff;
			}
		}

		.el-message--info .el-message__content,
		.el-message--error .el-message__content,
		.el-message--warning .el-message__content,
		.el-message--success .el-message__content {
			color: #fff;
		}

		// }
	}

	// 滚动条的滑块
	.el-table__body-wrapper::-webkit-scrollbar-thumb {
		background-color: #D1E3FF;
		border-radius: 3px;
	}

	.el-table__body-wrapper,
	.el-scrollbar__wrap {
		&::-webkit-scrollbar {
			width: 4px;
			height: 4px;
		}
	}

	.layer {

		// 暂无数据
		.no_data {
			img {
				width: 110px;
				height: auto;
				margin-bottom: 10px;
			}

			p {
				font-size: 16px;
				color: #999;
			}
		}
	}

	body .el-popover {
		min-width: 50px;
		background: #212A36;
		border-radius: 10px;
		border: 0;
		color: #fff;
	}
</style>